package cn.gjxblog.config;

import cn.gjxblog.model.UserContext;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author gjx
 * @version v1.0
 * @Description
 * @date 2018/12/11 14:14
 */
@Configuration
public class FeginConfiguration {

    @Bean
    public FeignBasicAuthRequestInterceptor basicAuthRequestInterceptor() {
        return new FeignBasicAuthRequestInterceptor();
    }

    public class FeignBasicAuthRequestInterceptor  implements RequestInterceptor {
        public FeignBasicAuthRequestInterceptor() {
        }
        @Override
        public void apply(RequestTemplate template) {
            if(UserContext.getUser()!=null){
                template.header("Authorization", UserContext.getUser().getToken());
            }

        }
    }
}
